﻿using IFRS.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace IFRS.DataAccess.DAL
{
    public class SPR_INVESTMENTFAIRVALUE
    {
        public DataTable SEARCH_ALL(InvestmentFairValue investmentFairValue, Paging paging, bool IFRS_ALLBRANCH, string sIFRS_COST_CENTER, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@isAllBranch", IFRS_ALLBRANCH));
                lstParams.Add(new SqlParameter("@sCostCenter", sIFRS_COST_CENTER));

                lstParams.Add(new SqlParameter("@TransactionDate", investmentFairValue.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@IndustryTypeID", investmentFairValue.IndustryTypeID.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_INVESTMENTFAIRVALUE_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int InvestmentFairValueID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@InvestmentFairValueID", InvestmentFairValueID));
                dt = Utility.StoredProcDataTable("SPR_INVESTMENTFAIRVALUE_SEARCHBYID", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(InvestmentFairValue investmentFairValue)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@InvestmentFairValueID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@TransactionDate", investmentFairValue.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@IndustryTypeID", investmentFairValue.IndustryTypeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@FairValue", investmentFairValue.FairValue.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedDate", investmentFairValue.CreatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBy", investmentFairValue.CreatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", investmentFairValue.CreatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBranch", investmentFairValue.CreatedBranch.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", investmentFairValue.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", investmentFairValue.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", investmentFairValue.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", investmentFairValue.UpdatedBranch.AsDBValue()));

                Utility.ExecuteStoredProc("SPR_INVESTMENTFAIRVALUE_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(InvestmentFairValue investmentFairValue)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@InvestmentFairValueID", investmentFairValue.InvestmentFairValueID.AsDBValue()));
                lstParams.Add(new SqlParameter("@TransactionDate", investmentFairValue.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@IndustryTypeID", investmentFairValue.IndustryTypeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@FairValue", investmentFairValue.FairValue.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", investmentFairValue.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", investmentFairValue.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", investmentFairValue.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", investmentFairValue.UpdatedBranch.AsDBValue()));

                iNum = (int)Utility.ExecuteStoredProc("SPR_INVESTMENTFAIRVALUE_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(InvestmentFairValue investmentFairValue)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@InvestmentFairValueID", investmentFairValue.InvestmentFairValueID.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", investmentFairValue.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", investmentFairValue.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", investmentFairValue.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", investmentFairValue.UpdatedBranch.AsDBValue()));
                iNum = (int)Utility.ExecuteStoredProc("SPR_INVESTMENTFAIRVALUE_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }
    }
}